package com.yc.springcloud.utils;


/**
 * @Author DELL
 * @Date 2024/8/29 12:17
 * @Version 1.0
 */

public class Result<T> {
	
	private String code;
	private String msg;
	private T data;

	public Result() {
	}

	//这里可以返回指定的data 扩展性
	public Result(T data) {
		this.data = data;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	@Override
	public String toString() {
		return "Result{" +
				"code='" + code + '\'' +
				", msg='" + msg + '\'' +
				", data=" + data +
				'}';
	}
	
	//编写方法返回需要的result方法
	public static Result success(){
		Result result = new Result();
		result.setCode("200");
		result.setMsg("success");
		return result;
	}

	//编写方法返回需要的result方法 泛型方法
	public static <T> Result<T> success(T data){
		Result<T> result = new Result<>(data);
		result.setCode("200");
		return result;
	}

	//编写方法返回需要的result方法 泛型方法
	public static <T> Result<T> success(String msg , T data){
		Result<T> result = new Result<>(data);
		result.setCode("200");
		result.setMsg(msg);
		return result;
	}

	//编写方法返回需要的result方法
	public static Result error(String code,String msg){
		Result result = new Result();
		result.setCode(code);
		result.setMsg("error");
		return result;
	}

	//编写方法返回需要的result方法(带参数)
	public static <T> Result<T> error(String code,String msg,T data){
		Result<T> result = new Result<>(data);
		result.setData(data);
		result.setCode(code);
		result.setMsg("error");
		return result;
	}
}
